<?php
/**
 * Created by PhpStorm.
 * User: 86159
 * Date: 2021/1/25
 * Time: 14:04
 */

namespace App\Services;


use App\Models\Company;
use App\Models\Job;
use Illuminate\Support\Facades\DB;

class JobServices extends BaseServices
{
    //找寻推荐的职位
    public function getHotJob(){
        $field = ['jobtitle','salary','special','companyid'];
       return Job::where('is_hot',1)->with(['company' => function ($query) {
            $query->select('id','companyname','thumb','companycate','province','city','area');
        }])->get($field);
    }
    //查询所有职位
    public function getAllJob(){
        return Job::query()->get();
    }
    //搜索对应职位
    public function searchJob($key){
        $res1 = Job::query()->where('jobtitle','like','%'.$key.'%')->with(['company' => function ($query) {
            $query->select('id','companyname','thumb','companycate','province','city','area');
        }])->get();
        if ($res1->isEmpty()){
            $ids = (new Company())->getIdsByName($key);
            if (!$ids->isEmpty()){
                $res1 = Job::query()->whereIn('companyid',$ids)->with(['company' => function ($query) {
                    $query->select('id','companyname','thumb','companycate','province','city','area');
                }])->get();
            }
        }
        return $res1 ?? '';
    }
}